package com.ido.otaclient.three;

import android.content.Context;

import com.ido.otaclient.base.BasePreference;
import com.ido.otaclient.env.AppEnv;

/**
 * Copyright (c) 2019 深圳市爱都科技有限公司. All rights reserved.
 *
 * @Author: xyb
 * @CreateDate: 2020-03-06 14:56
 * @description
 */
public class ThreeToOnePerfence extends BasePreference {
    private static final String NAME = "three_preference";

    private static final String TASK_NAME = "taskName";
    private static final String FIREWARE_SPECIAL_NAME = "firewareSpecialName";
    private static final String FIREWARE_SPECIAL_VERSION = "firewareSpecialVersion";
    private static final String FIREWARE_SPECIAL_PATH = "firewareSpecialPath";
    private static final String FIREWARE_NEW_NAME = "firewareNewName";
    private static final String FIREWARE_NEW_VERSION = "firewareNewVersion";
    private static final String FIREWARE_NEW_PATH = "firewareNewPath";
    private static final String FONT_NAME ="fontName";
    private static final String FONT_NAME_VERSION ="fontVersion";
    private static final String FONT_PATH = "fontPath";
    private static final String DEVICE_ID = "deviceId";
    private static final String PLATFORM_NAME = "platformName";
    /**
     * 升级配置
     */
    private ThreeToOneConfig mThreeToOneConfig;

    private static volatile ThreeToOnePerfence instance;

    private static Context getContext() {
        return AppEnv.instance().getContext();
    }

    public static ThreeToOnePerfence getInstance() {
        if (instance == null) {
            synchronized (ThreeToOnePerfence.class) {
                if (instance == null) {
                    instance = new ThreeToOnePerfence();
                }
            }
        }
        return instance;
    }

    /**
     * 保存配置在本地
     * @param threeToOneConfig
     */
    public void saveThreeToOneConfig(ThreeToOneConfig threeToOneConfig){
        if(threeToOneConfig == null){
            threeToOneConfig = new ThreeToOneConfig();
        }
        saveString(getContext(),NAME,TASK_NAME,threeToOneConfig.getTaskName());
        saveString(getContext(),NAME,FIREWARE_SPECIAL_NAME,threeToOneConfig.getFirewareSpecialName());
        saveString(getContext(),NAME,FIREWARE_SPECIAL_VERSION,threeToOneConfig.getFirewareSpecialVersion());
        saveString(getContext(),NAME,FIREWARE_NEW_NAME,threeToOneConfig.getFirewareNewName());
        saveString(getContext(),NAME,FIREWARE_NEW_VERSION,threeToOneConfig.getFirewareNewVersion());
        saveString(getContext(),NAME,FONT_NAME,threeToOneConfig.getFontName());
        saveString(getContext(),NAME,FONT_NAME_VERSION,threeToOneConfig.getFontVersion());
        saveString(getContext(),NAME,FIREWARE_SPECIAL_PATH,threeToOneConfig.getFirewareSpecialPath());
        saveString(getContext(),NAME,FIREWARE_NEW_PATH,threeToOneConfig.getFirewareNewPath());
        saveString(getContext(),NAME,FONT_PATH,threeToOneConfig.getFontPath());
        saveString(getContext(),NAME,DEVICE_ID,threeToOneConfig.getDeviceId());
        saveString(getContext(),NAME,PLATFORM_NAME,threeToOneConfig.getUploadPlatform());
        mThreeToOneConfig = threeToOneConfig;
    }

    /**
     * 从本地取出数据
     * @return
     */
    public ThreeToOneConfig getThreeToOneConfig(){
        mThreeToOneConfig = new ThreeToOneConfig();
        mThreeToOneConfig.setTaskName(getString(getContext(),NAME,TASK_NAME));
        mThreeToOneConfig.setFirewareSpecialName(getString(getContext(),NAME,FIREWARE_SPECIAL_NAME));
        mThreeToOneConfig.setFirewareSpecialVersion(getString(getContext(),NAME,FIREWARE_SPECIAL_VERSION));
        mThreeToOneConfig.setFirewareNewName(getString(getContext(),NAME,FIREWARE_NEW_NAME));
        mThreeToOneConfig.setFirewareNewVersion(getString(getContext(),NAME,FIREWARE_NEW_VERSION));
        mThreeToOneConfig.setFontName(getString(getContext(),NAME,FONT_NAME));
        mThreeToOneConfig.setFontVersion(getString(getContext(),NAME,FONT_NAME_VERSION));
        mThreeToOneConfig.setFirewareSpecialPath(getString(getContext(),NAME,FIREWARE_SPECIAL_PATH));
        mThreeToOneConfig.setFirewareNewPath(getString(getContext(),NAME,FIREWARE_NEW_PATH));
        mThreeToOneConfig.setFontPath(getString(getContext(),NAME,FONT_PATH));
        mThreeToOneConfig.setDeviceId(getString(getContext(),NAME,DEVICE_ID));
        mThreeToOneConfig.setUploadPlatform(getString(getContext(),NAME,PLATFORM_NAME));
        return mThreeToOneConfig;
    }
}
